#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: redis-list操作.py
@time: 2017/5/25 10:15
"""

import redis

pool = redis.ConnectionPool(host='192.168.6.248',port=63780,db=7,password='liang123456')  #连接池方式连接,用第6这个库
r = redis.Redis(connection_pool=pool)     #建立redis连接

# r.sadd('names2','Beam','Mity','Jack')
# print(r.scard('names'))
# print(r.smembers('names'))

# r.sadd('info1','Beam','Mity','Jack')
# r.sadd('info2','dog','Beam','cat')
# print(r.sdiff('info1','info2'))
# print(r.sdiff('info2','info1'))

# print(r.smembers('info1'))
# print(r.smembers('info2'))
# r.sdiffstore('info3','info1','info2')
# print(r.smembers("info3"))

# print(r.smembers("info1"))
# print(r.smembers("info2"))
# print(r.sinter('info1','info2'))

# r.sinterstore('info4','info1','info2')
# print(r.smembers('info4'))

# print(r.sismember('info1','Beam'))
# print(r.sismember('info1','Baam'))

# print(r.smembers('info3'))
# print(r.smembers('info4'))
# r.smove('info4','info3','Beam')
# print(r.smembers('info3'))
# print(r.smembers('info4'))

# print(r.smembers('info3'))
# r.spop('info3')
# print(r.smembers('info3'))

# r.sadd('names3','Beam','Mity','Jack','cat','dog','kity')
# print(r.smembers('names3'))
# print(r.srandmember('names3',2))

# print(r.smembers('info3'))
# r.srem('info3','Beam')
# print(r.smembers('info3'))

# print(r.smembers('info1'))
# print(r.smembers('info2'))
# print(r.sunion('info1','info2'))

# print(r.smembers('info1'))
# print(r.smembers('info2'))
# r.sunionstore('info6','info1','info2')
# print(r.smembers('info6'))

# print(r.smembers("names3"))
# print(r.sscan('names3'))

# for i in r.sscan_iter('names3'):print(i,)

r.zadd('zadd1',n1=11,n2=22,n3=33,n4=44,n5=55)
# r.zadd('zadd2','n1',11,'n2',22)

# print(r.zcard('zadd1'))

# print(r.zcount('zadd1',1,3))

# # r.zadd('zadd1',n1=11,n2=22,n3=33,n4=44,n5=55)
# print(r.zcount('zadd1',0,38))


# #r.zadd('source','Beam',89,'Mity',100,'Kitt',85)
# print(r.zscore('source','Beam'))
# r.zincrby('source','Beam',3)
# print(r.zscore('source','Beam'))


# print(r.zrange('source',0,-1,True,True,int))  #第一个True表示从大到小排序，反之从小到大，第二个True表示是否输出key的值，默认是float类型，这个变成int类型
# print(r.zrange('source',0,-1,False,False))

# print(r.zrange('source',0,-1,True,True,int))
# print(r.zrank('source','Mity'))
# print(r.zrevrank('source','Mity'))

# print(r.zrange('zadd1',0,-1,True,True,int))
# r.zrem('zadd1','n3')
# print(r.zrange('zadd1',0,-1,True,True,int))

# print(r.zrange('zadd1',0,-1,False,True,int))
# r.zremrangebyrank('zadd1',1,2)
# print(r.zrange('zadd1',0,-1,False,True,int))


# print(r.zrange('zadd1',0,-1,False,True,int))
# r.zremrangebyscore('zadd1',21,55)
# print(r.zrange('zadd1',0,-1,False,True,int))

# print(r.zrange('zadd1',0,-1,False,True,int))
# print(r.zscore('zadd1','n3'))

# r.zadd('source1','Beam',92,'Mity',100,'Kitt',85,'Boyt',78)
# r.zadd('source2','Cat',67,'Mitt',89,'Beam',89,'Mity',85)
# r.zadd('source3','Rose',79,'Mitt',89,'Beam',98,'Mity',88)
# r.zinterstore('newsource',('source1','source2','source3'),aggregate="SUM")  #key的交集并且把对应key的value相加
# print(r.zrange('newsource',0,-1,False,True,int))
# r.zinterstore('newsource',('source1','source2','source3'),aggregate="MIN")  #交集并且取key最少的值
# print(r.zrange('newsource',0,-1,False,True,int))
# r.zinterstore('newsource',('source1','source2','source3'),aggregate="MAX")  #交集并且取key最大的值
# print(r.zrange('newsource',0,-1,False,True,int))

# r.zadd('source1','Beam',92,'Mity',100,'Kitt',85,'Boyt',78)
# r.zadd('source2','Cat',67,'Mitt',89,'Beam',89,'Mity',85)
# r.zadd('source3','Rose',79,'Mitt',89,'Beam',98,'Mity',88)
# r.zunionstore('newsource',('source1','source2','source3'),aggregate="SUM")  #key的并集并且把对应key的value相加
# print(r.zrange('newsource',0,-1,False,True,int))
# r.zunionstore('newsource',('source1','source2','source3'),aggregate="MIN")  #并集并且取key最少的值
# print(r.zrange('newsource',0,-1,False,True,int))
# r.zunionstore('newsource',('source1','source2','source3'),aggregate="MAX")  #并集并且取key最大的值
# print(r.zrange('newsource',0,-1,False,True,int))

# print(r.zscan('newsource'))

for i in r.zscan_iter('newsource'): print(i)